/**
 * 二次封装Fetch请求接口
 * @param {*} url 请求地址
 * @param {*} param 请求负载
 * @returns Promise
 */
export default async function request(url, param) {
  const { method, headers = {}, data = {} } = param;
  const config = {
    method: method || 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...headers,
    },
    credentials: 'include',
  };
  config.method === 'POST' && (config.body = JSON.stringify(data));
  return fetch(url, config).then(res => res.json());
}
